package com.hundsun.yr.universal.p2p.utils;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.view.View;

import com.hundsun.yr.universal.library.base.BaseWebActivity;
import com.hundsun.yr.universal.library.base.BaseWebActivity.LoadType;
import com.hundsun.yr.universal.library.widget.HSToast;
import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.p2p.ui.activity.WebActivity;



/**
 * @Title: URLSpanNoUnderline.java 
 * @Description: 不带下划线的超链接
 * @date 2016-2-20 下午5:07:36 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class URLSpanNoUnderline extends ClickableSpan {

	/**上下文**/
	private Context mContext;
	/**标题**/
	private String mTitle;
	/**链接**/
	private String mUrl;
	/**是否显示底部栏**/
	private boolean SHOW_BOTTOM_BAR=true;
	public URLSpanNoUnderline(Context context,String title,String url) {
		this.mContext=context;
		this.mTitle=title;
		this.mUrl=url;
	}
	
	public URLSpanNoUnderline(Context context,String title,String url,boolean show_bottom_bar) {
		this.mContext=context;
		this.mTitle=title;
		this.mUrl=url;
		this.SHOW_BOTTOM_BAR=show_bottom_bar;
	}

	@Override
	public void onClick(View widget) {
		
		if(!TextUtils.isEmpty(mUrl)){
			
			Intent intent =new Intent(mContext,WebActivity.class);
			Bundle bundle =new Bundle();
			bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mTitle);
			bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, mUrl);
			bundle.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, LoadType.HTTP.getIntValue());
			bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, SHOW_BOTTOM_BAR);
			intent.putExtras(bundle);
			mContext.startActivity(intent);
		}else{
			new HSToast(mContext).showToast(R.string.tips_protocol);
		}
	}

	@Override
	public void updateDrawState(TextPaint ds) {
		super.updateDrawState(ds);
		ds.setUnderlineText(false); // 取消下划线
		ds.setColor(mContext.getResources().getColor(R.color.primary_cl_6)); // 指定文字颜色
	}

}